﻿using Finance.Api.Write.Applications.Commands.财务管理.Receives;
using Finance.Api.Write.Applications.Commands.财务管理.Refunds;
using Finance.Api.Write.Applications.Commands.财务管理.ReturnMonerys;
using Finance.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;

namespace Finance.Api.Write.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class ManagementController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<ManagementController> logger;

        public ManagementController(IMediator mediator, ILogger<ManagementController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 修改退款信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdataReturnMoney(UpdateReturnMoneryCommand request, CancellationToken cancellationToken)
        {

            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
            
        }

        /// <summary>
        /// 退款信息的新增
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddRewsultMoney(AddReturnMoneryCommand request, CancellationToken cancellationToken)
        {
            try
            {
                logger.LogInformation("退款信息的新增");
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
          
        }
        /// <summary>
        /// 付款信息的删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ApiResult<int>> DelRefund(RefundDelCommand request)
        {
            try
            {
                logger.LogInformation("删除成功");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
                
                throw;
            }
           
        }
        /// <summary>
        /// 付款信息修改
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ApiResult<int>> UpdataRefund(RefundUpdataCommand request, CancellationToken cancellationToken)
        {
            try
            {
                logger.LogInformation("付款信息修改");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
                throw;
            }
           
        }

        /// <summary>
        /// 付款管理添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddRefund(RefundAddCommand request)
        {

            try
            {
                logger.LogInformation("付款信息添加");
               return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
                throw;
            }
           
        }


        /// <summary>
        /// 收款管理添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<bool>> AddReceive(ReceiveAddCommand request)
        {

            try
            {
                var command =new ReceiveAddCommand();
                logger.LogInformation("收款信息添加成功");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("异常信息=》" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 收款管理修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<bool>> UpdataReceive(ReceiveUpdataCommand request)
        {
            try
            {
                logger.LogInformation("收款管理修改");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("错误信息=>" + ex.Message);
                throw;
            }
           
        }
        /// <summary>
        /// 收款管理逻辑删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<bool>> DelLoginReceive(ReceiveDelLoginCommand request)
        {
            try
            {
                logger.LogInformation("收款管理删除");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("错误信息=>" + ex.Message);
                throw;
            }
            
        }



    }
}
